#ifndef GROUPMEMBERSMODEL_H
#define GROUPMEMBERSMODEL_H

#include <QAbstractListModel>

#include "../../global/xnamespace.h"
#include "GroupMemberModel.h"

X_BEGIN_NAMESPACE

class GroupMembersModelPrivate : public QSharedData
{
public:
    QList<GroupMemberModel *> m_members;
    QMap<QString, GroupMemberModel *> m_membersById;
};

// 群成员列表模型
class GroupMemberListModel: public QAbstractListModel
{
    Q_OBJECT

public:
    GroupMemberListModel(QObject* parent = NULL);
    GroupMemberListModel(const GroupMemberListModel &src);
    GroupMemberListModel &operator =(const GroupMemberListModel& rhs);
    virtual ~GroupMemberListModel();

    static const char *qmlName();

public:
    virtual int rowCount(const QModelIndex &parent) const;
    virtual QVariant data(const QModelIndex &index, int role) const;
    virtual QHash<int, QByteArray> roleNames() const;

public:
    GroupMemberModel &addMember(const QString &bareJid, const QString &name, const QString &photo, PhotoType photoType);
    GroupMemberModel &saveMember(const QString &bareJid, const QString &name, const QString &photo, PhotoType photoType);

    Q_INVOKABLE QString stats() const;

private:
    static bool groupMemberLessThan(const GroupMemberModel *m1, const GroupMemberModel *m2);

private:
    QSharedDataPointer<GroupMembersModelPrivate> d;

private:
    QHash<int, QByteArray> m_roleNames;
    static const char* ROLE_NAMES[];
};

X_END_NAMESPACE

#endif // GROUPMEMBERSMODEL_H
